package dimension.starry.mixin;

import dimension.starry.event.Events;
import net.minecraft.entity.ItemEntity;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = ServerPlayerEntity.class, priority = 1001)
public class ServerPlayerEntityMixin {

    @Inject(method = "onScreenHandlerOpened", at = @At(value = "HEAD"), cancellable = true)
    public void onScreenHandlerOpened(ScreenHandler screenHandler, CallbackInfo callbackInfo) {
        ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
        if (!Events.PLAYER_OPEN_CONTAINER_EVENT.invoker().onPlayerOpenContainer(player, screenHandler)) {
            callbackInfo.cancel();
        }
    }

}
